#-----------------------------------#
# Replication of:
# Seeking Opportunity in the Knowledge Economy: Moving Places, Moving Politics?
# Valentina Consiglio, Thomas Kurer

# File: 7c_models_mechanisms_PC2

# Note: This file codes the models included in the mechanisms section of the paper based on the Amenities component (PC2) of the index. 
# It takes the following steps:
# (1) Main models (as in 5)
# (2) Analysis of symmetry of effects (up- vs. downward moves)
# (3) Analysis of economic and cultural mechanisms
# (4) Analysis of symmetry of economic and cultural mechanisms
# The data is loaded and prepared in 5_models_main_NUTS3; ensure the script was run before this file. 
#-----------------------------------#

#-------------------------------------------------------------------------------# 
#### Preparation ####
#-------------------------------------------------------------------------------# 

## Texreg input 
vec_gof_names <- c("Num. obs." = "N",
                   "Num. groups: pid" = "N individuals",
                   "Num. groups: syear" = "N years")


#-------------------------------------------------------------------------------# 
#### 1 | Main Models with Principal Component Amenities (PC2) ####
#-------------------------------------------------------------------------------# 

## Political integration and orientation ##

fe_main_polint_polor2_PC2 <-  list(
  "Volunteering (Yes/No)" = feols(ft_volunt_d ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) 
                                  | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Local political activism (Yes/No)" = feols(ft_localpol_d ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) 
                                              | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Voting in federal election (Yes/No)" = feols(votefedel_lead ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)
                                                | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009),
  
  "Party leaning (Yes/No)" = feols(partyleand2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)
                                   | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Party leaning intensity (0-5)" = feols(partyleanint ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)
                                          | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Political orientation (0 L – 10 R)" = feols(polor ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) 
                                               | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009),
  
  "Centre left party ID" = feols(centre_left2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) 
                                 | pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  
  "Centre right party ID" = feols(centre_right2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) |
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df)
)


texreg(fe_main_polint_polor2_PC2)


texreg(fe_main_polint_polor2_PC2, digits = 3,
       label = "tab:fe_main_polint_polor2_PC2",
       caption = "Opportunity moves and political integration and orientation (Urban Amenity Component)",
       custom.coef.map = list("pc2_01_wn" = "PC2"),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "/mechanisms/components/Appendix_Table_E47.tex"))



## Party identification ##

fe_main_partid2_PC2 <-  list(
  "SPD " = feols(spd_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "CDU/CSU " = feols(cducsu_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                       pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "Gruene " = feols(greens_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                      pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "FDP " = feols(fdp_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "Linke" = feols(linke_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df),
  "AfD " = feols(afd_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2014)
)

texreg(fe_main_partid2_PC2)


texreg(fe_main_partid2_PC2, digits = 3,
       label = "tab:fe_main_partid2_PC2",
       caption = "Opportunity moves and party identification (Urban Amenity Component)",
       custom.coef.map = list("pc2_01_wn" = "PC2"),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                            
       custom.note = paste("%stars. Party leanings include coalitions in the political direction of the respective party (i.e., including left coalitions for SPD, Gruene, and Linke; right coalitions for CDU/CSU, FDP, and AfD). All models include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2010-2020."),
       file = paste0(tables_path, "/mechanisms/components/Appendix_Table_E48.tex"))


#-----------------------------------------------------------------------------------------------------#




#-----------------------------------------------------------------------------------------------------#
#### 2 | Symmetry of Effects ####
#-----------------------------------------------------------------------------------------------------#

#-----------------------------------------------------------------------------------------------------#
##### 2.1 | Upward move  #####
#-----------------------------------------------------------------------------------------------------#

#-----------------------------------------------------------------------------------------------------#

## Opportunity moves and political integration and orientation ##

# Without multiple movers

# Unbalanced
fe_main_polint_polor2_upmove_ub2_only_PC2 <-  list(
  "Volunteering (Yes/No)" = feols(ft_volunt_d ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Local political activism (Yes/No)" = feols(ft_localpol_d ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Voting in federal election (Yes/No)" = feols(votefedel_lead ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009_upmove_ub2),
  
  "Party leaning (Yes/No)" = feols(partyleand2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| 
                                     pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Party leaning intensity (0-5)" = feols(partyleanint ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| 
                                            pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Political orientation (0 L – 10 R)" = feols(polor ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                 pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009_upmove_ub2),
  
  "Centre left party ID" = feols(centre_left2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  
  "Centre right party ID" = feols(centre_right2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2)
)


texreg(fe_main_polint_polor2_upmove_ub2_only_PC2)

texreg(fe_main_polint_polor2_upmove_ub2_only_PC2, digits = 3,
       label = "tab:fe_main_polint_polor2_upmove_ub2_only_PC2",
       caption = "Upward opportunity moves and political integration and orientation (Urban Amenity Component)",
       custom.coef.map = list('pc2_01_wn' = 'PC2'),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models are restricted to one-time upward movers and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "/mechanisms/components/Appendix_Table_E49.tex"))



fe_main_partid2_upmove_ub2_only_PC2 <-  list(
  "SPD" = feols(spd_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "CDU/CSU" = feols(cducsu_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                      pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "Gruene" = feols(greens_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                     pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "FDP" = feols(fdp_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "Linke" = feols(linke_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_upmove_ub2),
  "AfD" = feols(afd_co2 ~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2014_upmove_ub2)
)

texreg(fe_main_partid2_upmove_ub2_only_PC2)


texreg(fe_main_partid2_upmove_ub2_only_PC2, digits = 3,
       label = "tab:fe_main_partid2_upmove_ub2_only_PC2",
       caption = "Upward opportunity moves and party identification (Urban Amenity Component)",
       custom.coef.map = list('pc2_01_wn' = 'PC2'),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                            
       custom.note = paste("%stars. All models are restricted to one-time upward movers and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "/mechanisms/components/Appendix_Table_E50.tex"))



#-----------------------------------------------------------------------------------------------------#
##### 2.2 | Downward move  #####
#-----------------------------------------------------------------------------------------------------#

# Unbalanced
fe_main_polint_polor2_downmove_ub2_only_PC2 <-  list(
  "Volunteering (Yes/No)" = feols(ft_volunt_d ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Local political activism (Yes/No)" = feols(ft_localpol_d ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Voting in federal election (Yes/No)" = feols(votefedel_lead ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009_downmove_ub2),
  
  "Party leaning (Yes/No)" = feols(partyleand2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| 
                                     pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Party leaning intensity (0-5)" = feols(partyleanint ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| 
                                            pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Political orientation (0 L – 10 R)" = feols(polor ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                                 pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2009_downmove_ub2),
  
  "Centre left party ID" = feols(centre_left2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                   pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  
  "Centre right party ID" = feols(centre_right2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2)
)


texreg(fe_main_polint_polor2_downmove_ub2_only_PC2)

texreg(fe_main_polint_polor2_downmove_ub2_only_PC2, digits = 3,
       label = "tab:fe_main_polint_polor2_downmove_ub2_only_PC2",
       caption = "Downward opportunity moves and political integration and orientation (Urban Amenity Component)",
       custom.coef.map = list('pc2_01_wn_rc' = 'PC2 (rev)'),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models are restricted to one-time downward movers and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "/mechanisms/components/Appendix_Table_E51.tex")
)



fe_main_partid2_downmove_ub2_only_PC2 <-  list(
  "SPD" = feols(spd_co2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "CDU/CSU" = feols(cducsu_co2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                      pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "Gruene" = feols(greens_co2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                     pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "FDP" = feols(fdp_co2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "Linke" = feols(linke_co2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                    pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_downmove_ub2),
  "AfD" = feols(afd_co2 ~ pc2_01_wn_rc + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype) | 
                  pid + syear, panel.id = ~pid + syear, cluster = "krs", data = df_2014_downmove_ub2)
)

texreg(fe_main_partid2_downmove_ub2_only_PC2)


texreg(fe_main_partid2_downmove_ub2_only_PC2, digits = 3,
       label = "tab:fe_main_partid2_downmove_ub2_only_PC2",
       caption = "Downward opportunity moves and party identification (Urban Amenity Component)",
       custom.coef.map = list('pc2_01_wn_rc' = 'PC2 (rev)'),
       custom.gof.rows = list("Individual fixed-effects" = c("YES", "YES", "YES", "YES", "YES", "YES"), "Time fixed-effect" = c("YES", "YES", "YES", "YES", "YES", "YES")),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                            
       custom.note = paste("%stars. All models are restricted to one-time downward movers and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009/10-2020."),
       file = paste0(tables_path, "/mechanisms/components/Appendix_Table_E52.tex"))



#-------------------------------------------------------------------------------# 
#### 3 | Economic and Cultural Mechanisms ####

#-------------------------------------------------------------------------------# 

##### 3.1 | Economic #####


# Main #
econ_DVs <- c("ln_pglabgro2", "pgisei08", "worr_wpsec")

names_econ_DVs <- c(ln_pglabgro2 = "Log gross monthly earnings", 
                    pgisei08 = "ISEI-score",
                    worr_wpsec = "Worries about job security"
)


fe_mech_econ_PC2 <- list()

# Loop over econ CVs
for (econ_DV in econ_DVs) {
  
  # Define model
  formula <- as.formula(paste(econ_DV, "~ pc2_01_wn + pgexpft + pgexpft^2 + as.factor(educ_h) + as.factor(hhtype)| pid + syear"))
  
  # Run regression 
  fe_mech_econ_PC2[[names_econ_DVs[[econ_DV]]]] <- feols(formula, panel.id = ~pid + syear, cluster = "krs", data = df_2009)
}

texreg(fe_mech_econ_PC2)
texreg(fe_mech_econ_PC2, digits = 3,
       label = "tab:fe_mech_econ_PC2",
       caption = "Opportunity moves: Socio-economic Outcomes (Urban Amenity Component)",
       custom.coef.map = list('pc2_01_wn' = 'PC2'),
       custom.gof.rows = list("Individual fixed-effects" = rep("YES", length(fe_mech_econ_PC2)), 
                              "Time fixed-effect" = rep("YES", length(fe_mech_econ_PC2))),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models include work experience, work experience squared, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E53a.tex"))


#------------------------------------------------------------------------------#
##### 3.2 | Cultural #####
#------------------------------------------------------------------------------#

# DVs on cultural variables

cult_DVs <- c("ft_opera_d", "ft_cinema_d","ft_artmus_d") # 

names_cult_DVs <- c(ft_opera_d = "Cultural events (dummy)", 
                    ft_cinema_d = "Cinema, concerts, clubs (dummy)", 
                    ft_artmus_d = "Artistic/musical activities (dummy)"
)

# , ft_index_cult = "Cultural activities (index)"

fe_mech_culture_PC2 <- list()

# Loop over cult CVs
for (cult_DV in cult_DVs) {
  
  # Define model
  formula <- as.formula(paste(cult_DV, "~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| pid + syear"))
  
  # Run regression 
  fe_mech_culture_PC2[[names_cult_DVs[[cult_DV]]]] <- feols(formula, panel.id = ~pid + syear, cluster = "krs", data = df_2009)
}


texreg(fe_mech_culture_PC2)
texreg(fe_mech_culture_PC2, digits = 3,
       label = "tab:fe_mech_culture_PC2",
       caption = "Opportunity moves: Cultural Outcomes (Urban Amenity Component)",
       custom.coef.map = list('pc2_01_wn' = 'PC2'),
       custom.gof.rows = list("Individual fixed-effects" = rep("YES", length(fe_mech_culture_PC2)), 
                              "Time fixed-effect" = rep("YES", length(fe_mech_culture_PC2))),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. All models are linear probability models and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E53b.tex"))


#------------------------------------------------------------------------------#
##### 3.3 | Upward Econ #####
#------------------------------------------------------------------------------#


# Main #
econ_DVs <- c("ln_pglabgro2", "pgisei08", "worr_wpsec")

names_econ_DVs <- c(ln_pglabgro2 = "Log gross monthly earnings", 
                    pgisei08 = "ISEI-score",
                    worr_wpsec = "Worries about job security"
)
# ue_d = "Unemployed (registered)"

fe_mech_econ_upmove_ub2_PC2 <- list()

# Loop over econ CVs
for (econ_DV in econ_DVs) {
  
  # Define model
  formula <- as.formula(paste(econ_DV, "~ pc2_01_wn + pgexpft + pgexpft^2 + as.factor(educ_h) + as.factor(hhtype)| pid + syear"))
  
  # Run regression 
  fe_mech_econ_upmove_ub2_PC2[[names_econ_DVs[[econ_DV]]]] <- feols(formula, panel.id = ~pid + syear, 
                                                                cluster = "krs", data = df_2009_upmove_ub2)
}


texreg(fe_mech_econ_upmove_ub2_PC2, digits = 3,
       label = "tab:fe_mech_econ_upmove_ub2_PC2",
       caption = "Upward opportunity moves: Socio-economic Outcomes (Urban Amenity Component)",
       custom.coef.map = list('pc2_01_wn' = 'PC2'),
       custom.gof.rows = list("Individual fixed-effects" = rep("YES", length(fe_mech_econ_upmove_ub2_PC2)), 
                              "Time fixed-effect" = rep("YES", length(fe_mech_econ_upmove_ub2_PC2))),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. The sample is restricted to upward moves only. All models include work experience, work experience squared, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E54a.tex"))


#------------------------------------------------------------------------------#
##### 3.4 | Upward Cult #####
#------------------------------------------------------------------------------#


cult_DVs <- c("ft_opera_d", "ft_cinema_d","ft_artmus_d")

names_cult_DVs <- c(ft_opera_d = "Cultural events (dummy)", 
                    ft_cinema_d = "Cinema, concerts, clubs (dummy)", 
                    ft_artmus_d = "Artistic/musical activities (dummy)"
)


fe_mech_culture_upmove_ub2_PC2 <- list()

# Loop over cult CVs
for (cult_DV in cult_DVs) {
  
  # Define model
  formula <- as.formula(paste(cult_DV, "~ pc2_01_wn + as.factor(age_grp3) + as.factor(educ_h) + as.factor(hhtype)| pid + syear"))
  
  # Run regression 
  fe_mech_culture_upmove_ub2_PC2[[names_cult_DVs[[cult_DV]]]] <- feols(formula, panel.id = ~pid + syear, 
                                                                   cluster = "krs", data = df_2009_upmove_ub2)
}

texreg(fe_mech_culture_upmove_ub2_PC2, digits = 3,
       label = "tab:fe_mech_culture_upmove_ub2_PC2",
       caption = "Upward opportunity moves: Cultural Outcomes (Urban Amenity Component)",
       custom.coef.map = list('pc2_01_wn' = 'PC2'),
       custom.gof.rows = list("Individual fixed-effects" = rep("YES", length(fe_mech_culture_upmove_ub2_PC2)), 
                              "Time fixed-effect" = rep("YES", length(fe_mech_culture_upmove_ub2_PC2))),
       stars = c(0.01, 0.05, 0.1), include.rsquared = F, include.adjrs = F,
       custom.gof.names = vec_gof_names,                                             
       custom.note = paste("%stars. The sample is restricted to upward moves only. All models are linear probability models and include age group, education group, and household type as control variables; Standard errors are clustered at the Kreis-level. Source: SOEP v.37, 2009-2020."),
       file = paste0(tables_path, "mechanisms/components/Appendix_Table_E54b.tex"))




#-------------------------------------------------------------------------------# 
# Remove all model lists from storage
rm(list = ls(pattern = "^fe_"))
#-------------------------------------------------------------------------------# 
# Clear workspace
rm(list=ls())
#-------------------------------------------------------------------------------# 

